package com.keti.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.keti.pojo.User;
import com.keti.DaoImpl.UserDaoImpl;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		    request.setCharacterEncoding("utf-8");
			String account = request.getParameter("account");
			String password = request.getParameter("password");
			User u = null;
			u = new UserDaoImpl().Login(account, password);
			int id = u.getId();
			if(u!=null && u.getIdentity().equals("用户")) {
				request.setAttribute("id", id);
				request.getRequestDispatcher("UserInterfaceServlet").forward(request, response);
			}else if(u!=null && u.getIdentity().equals("管理员")){
				response.sendRedirect("AdminInterfaceServlet");
			}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
